﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>管理系统 - 管理中心</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- <meta ng-include="'head.html'"> -->
    <style type="text/css">
        .table .input-group-btn>.btn{ height:30px; margin-top:0px;}
        .table>thead>tr>th{padding-bottom: 0px}
        .lineInfo { height:40px }
        .lineInfo>label{font-weight: 100 }
        .titleHead { font-family: 宋体; font-size: 16px; font-weight: 400; margin-left: 15px }
        .mt20{ margin-top: 20px }
        .mt40{ margin-top: 40px }
        .pHead{ color:#19B5FE }
        .content{ margin-left: 20px; font-size: 14px; font-family: arial; color:#1874CD; cursor: pointer; }
        .status{ font-size: 12px;  }
        .lineInfo>.btn{ border-radius:5px; }
        .desp{ font-size: 12px; margin-left: 10px }
    </style>
    <link rel="stylesheet" type="text/css" href="../lib/css/footable.bootstrap.min.css">
    <script src="../lib/js/jquery.min.js" type="text/javascript"></script>
    <script src="../js/build.js" type="text/javascript"></script>
    <script src="../js/public.js" type="text/javascript"></script>
</head>
<body class="flat-blue">
<div class="app-container" ng-app="myApp" ng-controller="myCtrl">
<div class="row content-container">
<div ng-include="'menus.html'" onload="loadReady()"></div>
<div class="container-fluid">
<div class="side-body padding-top" id="main" style="padding-top:65px">
    <!------------------Main---------------->
    <div style="width:99%; margin:0px 10px 20px 10px; height:100%;
                            opacity:1;background-color:#fff; ">
        
        <!--账号信息-->
        <div class="panel panel-default mt20">
            <div class="panel-heading pHead">
                账户
            </div>
            <div class="panel-body">
                <div>
                    <div class="col-md-4 lineInfo"><label>会员认证</label><label style="color:{{u.color}}" class="content">{{levelText}}</label> <span class="desp">（当前等级）</span></div>
                    <div class="col-md-4 lineInfo"><label class="status">状态</label><label class="content">{{statusLevel}}</label></div>
                    <div class="col-md-4 lineInfo">
                        <button type="button" ng-disabled="flagLevel" class="btn btn-info" style="text-shadow: black 5px 3px 3px;" ng-click="addAccount();">
                          <span class="glyphicon glyphicon-fire"></span> 申请
                        </button>
                        <label class='desp'>* 申请升级账户权限</label>
                    </div>
                </div>
            </div>
            <div class="panel-body">
                <div>
                    <div class="col-md-4 lineInfo"><label>公司认证</label><label class="content">{{company}}</label></div>
                    <div class="col-md-4 lineInfo"><label class="status">状态</label><label class="content red">{{statusCompany}}</label></div>
                    <div class="col-md-4 lineInfo">
                        <button type="button" ng-disabled="flagCompany" class="btn btn-info" style="text-shadow: black 5px 3px 3px;" ng-click="addCompany();">
                          <span class="glyphicon glyphicon-star"></span> 申请
                        </button>
                        <label class='desp'>*认证后可编辑该公司所有数据</label>
                    </div>
                </div>
            </div>
        </div>

        <!--基本信息-->
        <div class="panel panel-default" style="padding-left:0px">
            <div class="panel-heading pHead">
                公司信息
                <i class="fa fa-edit pull-right pointer" ng-click="editCompany()" style="color:#22A7F0"> 编辑</i>
            </div>
            <div class="panel-body">
                <div>
                    <div class="col-md-6 lineInfo"><label>公司名</label><label class="content">{{company}}</label></div>
                    <div class="col-md-6 lineInfo"><label>省份</label><label class="content">{{Addrs.address.selProvince}}</label></div>
                </div>
                <div>
                    <div class="col-md-6 lineInfo"><label>城市</label><label class="content">{{Addrs.address.selCity}}</label></div>
                    <div class="col-md-6 lineInfo"><label>详细地址</label><label class="content">{{line.address}}</label></div>
                </div>
                <div>
                    <div class="col-md-6 lineInfo">
                        <label>负责人</label>
                        <label class="content">
                            <a href="userInfo.html?u={{cp.editUser}}">{{line.editUser}}</a>
                        </label>
                    </div>
                    <div class="col-md-6 lineInfo"><label>设备数量</label><label class="content">{{line.count}}</label></div>
                </div>
                <div>
                    <div class="col-md-6 lineInfo"><label>联系电话</label><label class="content">{{line.telephone}}</label></div>
                    <div class="col-md-6 lineInfo"><label>备注</label><label class="content">{{line.other}}</label></div>
                </div>
            </div>
        </div>
        
    </div>

    <!-- 模态对话框 -->
    <div ng-include="'modalCompany.html'"></div>
    <!-- End · 模态对话框 -->

    <!------------------End Main---------------------->
</div>  <!--End side-body-->
</div>  <!--End container-fluid-->
</div>  <!--End content-container-->
<div ng-include="'footer.html'"></div>
</div>  <!--End app-container-->


<script language="javascript">
    var app = angular.module('myApp', []);
    
    app.controller('myCtrl', function($scope) {
        loadCtlBase($scope);
        $scope.line = { };
        $scope.statusLevel = '无';
        $scope.statusCompany = '无';
        $scope.flagLevel = false;
        $scope.flagCompany = false;

        loadUserAccount();
        loadUserCompany();

        //loadCompany();
        var status = ['审核中', '已通过', '未通过'];

        $scope.Addrs = {'address': {"selProvince":"", "selCity":"", "selCounty":""} };
        loadAddrs($scope, $scope.Addrs);
        $scope.cols = [];

        function getCols(obj){
            $scope.cols.push({'name':'公司', 'field': 'companyName', 'type':'label' });
            $scope.cols.push({'name':'地址', 'field': 'address', 'type':'address' });
            $scope.cols.push({'name':'联系电话', 'field': 'telephone', 'type':'text' });
            $scope.cols.push({'name':'备注', 'field': 'other', 'type':'text' });
            
            $scope.Addrs['address'].selProvince = obj.province;
            $scope.Addrs['address'].selCity = obj.city;
            $scope.Addrs['address'].selCounty = obj.county;
            $scope.updateAddrs("address");     //// 地址组件赋值手动赋值完
        }

        //// 加载公司详情信息
        function loadCompany(){
            ajaxData('get_company_info', {companyName:$scope.company}, function(rst){
                var d = rst.data.company, lines = rst.data.lines;   cout(rst);
                $scope.line = d;
                $scope.line['count'] = lines.length;
                getCols($scope.line);
                
                $scope.$apply();
            });
        }
        //// 加载账户认证信息
        function loadUserAccount(){
            ajaxData('get_user_account', {}, function(rst){
                var d = rst.data;
                $scope.level = d.level;
                $scope.levelText = getLevelText(d.level);
                if('status' in d){
                    $scope.statusLevel = status[d.status];
                    if(d.status==0)$scope.flagLevel = true;
                }
                $scope.$apply();
            });
        };
        //// 加载公司认证信息
        function loadUserCompany(){
            ajaxData('get_user_company', {}, function(rst){
                var d = rst.data;
                $scope.user = d.user;
                $scope.company = d.company;
                if(d.editUser==d.user){
                    $scope.statusCompany = '已认证！';
                    $scope.flagCompany = true;
                }else{
                    if('status' in d){
                        $scope.statusCompany = status[d.status];
                        if(d.status==0)$scope.flagCompany = true;
                    }else{
                        $scope.statusCompany = '未认证';
                    }
                }
                $scope.$apply();
                if($scope.company!='' && $scope.company)loadCompany();
            });
        };

        //// 提交公司认证信息
        $scope.addCompany = function (){
            ajaxData('add_user_company', {'company':$scope.company}, function(rst){
                $scope.statusCompany = status[0];
                $scope.flagCompany = true;
                $scope.$apply();
            });
        };

        //// 提交账户认证信息
        $scope.addAccount = function() {
            if($scope.level>=4){
                alert("您的权限已经很高了！");
                return;
            }
            
            ajaxData('add_user_account', {'level':$scope.level}, function(rst){
                $scope.statusLevel = status[0];
                $scope.flagLevel = true;
                $scope.$apply();
            });
        };

        //// 提交账户认证信息
        $scope.setCompany = function() {
            $scope.line['province'] = $scope.Addrs['address'].selProvince;
            $scope.line['city'] = $scope.Addrs['address'].selCity;
            $scope.line['county'] = $scope.Addrs['address'].selCounty;
            $scope.line['module'] = 'user';
            var dt = {'company':$scope.company, cp:JSON.stringify($scope.line)};
            // cout(dt);
            ajaxData('set_company_info', dt, function(rst){
                if(rst.data!=0){
                    alert("修改失败，请检查资料");
                }

                $("#myModal1").modal('hide');
            });
        };


        //// 增加字段
        $scope.editCompany = function(){
            $("#myModal1").modal('show');
        };


    });




</script>

</body>
</html>
